package com.xiguanlezz.cn;

/**
 * @Author：习惯了种种
 * @CreateDate：2024/11/4 14:39
 * @Description：填充字符串的工具类
 */
public class StringPaddingUtils {

    public static final char PADDING_CHAR = '#';

    public static final int STRING_MAX_LENGTH = 16;

    public static String paddingString(String str, int fixedLenth) {
        str = str == null ? "" : str;
        if (str.length() > fixedLenth) {
            throw new RuntimeException("str: " + str + " is too long");
        }

        int needPaddingLen = fixedLenth - str.length();
        StringBuilder sb = new StringBuilder();
        while (sb.length() < needPaddingLen) {
            sb.append(PADDING_CHAR);
        }
        sb.append(str);
        assert sb.length() == fixedLenth;
        return sb.toString();
    }
}
